import api from './api.js';

const setDot = function(name) {
	console.log('系统打点名称', name);
	console.log('uni.getSystemInfo', uni.getSystemInfo);
	let params = {
		jvjj: uni.getStorageSync('userId') || '-1', //已登录就必填
		ceoe: name, //optType 事件名称//必填
		ncem: '', //gpsInfo gps 信息
		lxoi: '', //lbs 经纬度
		cdsl: '', //equipmentBrand 设备品牌 //必填
		bgdw: '', //equipmentType 设备类型 //必填
		psio: '', //imei  imei
		esdm: '', //uuid
		jpdx: '', //os_version 系统版本 //必填
		jqgk: '', //user_agent
		zdxj: '', //mobile_language 
		simh: '', //扩展数据
		nkif: uni.getStorageSync('gaid') || '',
		googleMobileNo: uni.getStorageSync('phoneNo') //必填 【文档中没有额外增加】
	}
	// #ifndef H5
	const appTool = uni.requireNativePlugin('AppTool');
	appTool.getHardwareInfo((res) => {
		// console.log('系统埋点的插件', res);
		// console.log('系统语言', uni.getSystemInfoSync());
		let systemlang = uni.getSystemInfoSync()
		params.jpdx = res.os
		params.cdsl = res.brand
		params.bgdw = res.model
		params.zdxj = systemlang.language
	});
	// #endif

	api.SetDot(params).then(data => {
		console.error('系统打点成功', name);
	}).catch(error => {
		console.error('系统打点失败', name);
	});
	// 接入 Adjust，仅非 H5 平台
	// #ifndef H5
	const adj = uni.requireNativePlugin('sn-adjust');
	console.log('准备adjust', adj);
	const adjustEventMap = {
		CLICK_BASIC_INF_SUBMIT: 'xcamhm',
		CLICK_WORK_INF_SUBMIT: 'jdtgxb',
		CLICK_UP_BANK_INF_SUBMIT: 'lwjoji',
		CLICK_LOAN_SUBMIT: 'xkfn4s',
		CLICK_INDEX_APPLY_SUBMIT: '2mo6o2',
		CLICK_FIRST_INDEX_APPLY_SUBMIT: 'wfyht2',
		CLICK_LOGIN_SUBMIT: '766qmi',
		CLICK_CONFITM_SUBMIT: '7ul9yd',
		CLICK_FIRST_CONFITM_SUBMIT: 'u7qfya',
		CLICK_CONTACT_INF_SUBMIT: '4jrugy',
		CLICK_LOGIN_CODE_SUCCESS: 'd08jx7',
		CLICK_ID_INF_SUBMIT: '6apnc3',
		CLICK_ID_PICTURE_F_SUBMIT: 'j5pj14',
		CLICK_AMOUNT_SUBMIT: '7eerjj',
		CLICK_BANK_INF_SUBMIT: 'ofltib',
	};

	const token = adjustEventMap[name];
	if (token) {
		name == 'CLICK_LOGIN_SUBMIT' && console.log('开始登录打点');
		adj.trackEvent({
			eventToken: token
		});
		name == 'CLICK_LOGIN_SUBMIT' && console.log('结束登录打点');
	}
	// #endif

};




export default setDot